import axios from "axios";
import { App } from "antd";
export default function useRequest() {
  const { message } = App.useApp();
  const { token } = useUserStore();
  const request = axios.create({
    baseURL: import.meta.env.VITE_BASE_URL,
    timeout: 10000,
  });
  request.interceptors.request.use(
    (config) => {
      if (token) {
        config.headers["Authorization"] = `Bearer ${token}`;
      }
      return config;
    },
    (error) => {
      return Promise.reject(error);
    }
  );
  request.interceptors.response.use(
    (response) => {
      return response.data;
    },
    (error) => {
      return Promise.reject(error);
    }
  );
  return request;
}
